package com.kpx.app.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RadioGroup;

import com.kpx.app.R;
import com.kpx.app.adapter.MyPagerAdapter;
import com.kpx.app.base.ActivityBase;
import com.kpx.app.view.TitleView;
import com.kpx.app.view.ViewVipGrade;
import com.kpx.app.view.ViewVipPoint;
import com.kpx.app.view.ViewVipPrise;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by congdy on 17/3/6.
 * 会员中心
 */

public class ActivityVipCenter extends ActivityBase {
    @BindView(R.id.titleview)
    TitleView titleview;
    @BindView(R.id.group_task)
    RadioGroup group_task;
    @BindView(R.id.vp_content)
    ViewPager vp_content;
    /**
     * 用于装内容页面
     */
    private List<View> listViews;
    /**
     * 上一个所选择的菜单项页面
     */
    private int before_pager;
    /**
     * 上一个内容部分
     */
    protected int before;
    @Override
    public void initview(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_vip_center);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
// 初始化选项-------------------------------------------
        before_pager = R.id.radio_grade;// 默认初始显示第一个页面
        before = 0;// 设置初始选择的菜单

        // 初始化数据-------------------------------------------
        listViews = new ArrayList<View>();// 用于装内容页面
        ViewVipGrade vipGrade = new ViewVipGrade(this);
        ViewVipPoint vipPoint = new ViewVipPoint(this);
        ViewVipPrise vipPrise = new ViewVipPrise(this);
        listViews.add(vipGrade);
        listViews.add(vipPoint);
        listViews.add(vipPrise);

        vp_content.setAdapter(new MyPagerAdapter(listViews));// 设置viewpager的适配器
        vp_content.setCurrentItem(before);// 设置默认位置
        vp_content.setOnPageChangeListener(new MyOnPageChangeListener());// 设置viewpager的监听事件
        group_task.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.radio_grade:
                        vp_content.setCurrentItem(0);
                        break;
                    case R.id.radio_rule_point:
                        vp_content.setCurrentItem(1);
                        break;
                    case R.id.radio_rule_prise:
                        vp_content.setCurrentItem(2);
                        break;
                }
            }
        });
    }

    @Override
    public void onReceiver(Context context, Intent intent) {

    }
    /**
     * 用于监听页面的滑动
     *
     * @author chencong
     * @Description TODO
     * @date 2015年1月10日
     * @Copyright: Copyright (c) 2015 Shenzhen Tentinet Technology Co., Ltd. Inc. All rights reserved.
     */
    public class MyOnPageChangeListener implements ViewPager.OnPageChangeListener {

        @Override
        public void onPageSelected(int arg0) {
            switch (arg0) {
                case 0:
                    before_pager = R.id.radio_grade;
                    break;
                case 1:
                    before_pager = R.id.radio_rule_point;
                    break;
                case 2:
                    before_pager = R.id.radio_rule_prise;
                    break;
            }
            group_task.check(before_pager);// 设置指定位置的选中状态
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    }
}
